//
//  JSONModel+EXTMethod.m
//  DeyiLife
//
//  Created by zxin on 15/7/2.
//  Copyright (c) 2015年 Deyi. All rights reserved.
//

#import "JSONModel+EXTMethod.h"

@implementation JSONModel (EXTMethod)

+ (NSString *)getDataFromDict:(NSDictionary *)dict forKey:(NSString *)key {
    NSString *string = [dict objectForKey:key];
    return string;
}

+ (void)addDatasFromDict:(NSDictionary *)dict withModel:(NSString *)modelName forKey:(NSString *)key target:(NSMutableArray *)target isAppend:(BOOL)append {
    if (!append) {
        [target removeAllObjects];
    }
    if (!dict)
        return;
    
    NSArray *array = [dict objectForKey:key];
    if (!array)
        return;
    if ([array count] > 0) {
        for (NSUInteger i = 0; i < [array count]; i++) {
            NSDictionary *dictOne = array[i];
            NSError *err = nil;
            if (dictOne.count > 0) {
                id model = [[NSClassFromString(modelName) alloc] initWithDictionary:dictOne error:&err];
                if (!err) {
                    [target addObject:model];
                }
            }
        }
    }
}

@end
